/**
 * Created by HeartFul on 2014/8/14.
 */
var zhgl = function () {
    canRefresh =false;
    $(".dt_warp").remove();
    LeftTime = 1;
    var userInfo = JSON.parse(window.localStorage.userInfo);

    var dt_warp = d3.select("body").append("div").classed("dt_warp", true).style({
        height: "100%",
        "overflow": "hidden"
    });
    var sz_bg = dt_warp.append("div").classed("sz_bg", true);
    var datong_header = sz_bg.append("div").classed("datong_header", true);
    datong_header.append("h1").html("账号信息");
    var setting_con = sz_bg.append("div").classed("setting_con", true);
    var user_info = setting_con.append("div").classed("user_info", true);
    var p = user_info.append("p");
    p.append("img").attr("src", picURL).style({
        width: "95px",
        height: "110px"
    }).attr("alt", "../../common/page/images/user_ico.png");
    var dl = user_info.append("dl");
    dl.append("dt").html("姓名：");
    dl.append("dd").attr("id", "userName").html(userInfo["userName"] || "--");
    dl.append("dt").html("单位：");
    dl.append("dd").attr("id", "partyName").html(userInfo["orgName"] || "--");
    dl.append("dt").html("手机：");
    dl.append("dd").html((userInfo["mobile"] || "--"));
    dl.append("dt").html("电话：");
    dl.append("dd").html((userInfo["phone"] || "--"))
    var ul = setting_con.append("ul");
    /*   var li = ul.append("li").attr("id", "anqsz");
     li.append("p").html("安全设置");
     li.append("span");*/
	li = ul.append("li").attr("id", "mimcz");
    li.append("p").html("修改密码");
    li.append("span");
	//edit by lixuefang 20160518,添加常用语管理模块
	li = ul.append("li").attr("id", "changyy");
    li.append("p").html("常用语管理");
    li.append("span");
    li = ul.append("li").attr("id", "guanywm");
    li.append("p").html("关于我们");
    li.append("span");
    li = ul.append("li").attr("id", "banbgx");
    li.append("p").html("版本更新");
    li.append("span");
    /*   li = ul.append("li").attr("id", "yonghbz");
     li.append("p").html("用户帮助");
     li.append("span");*/
    var footer = dt_warp.append("div").classed("footer", true).style({
        position: 'absolute', bottom: '0px'
    });
    footer.append("div").classed("f_navone", true).attr("type", "button").append("span");
    footer.append("div").classed("f_navtwo", true).attr("type", "button");
    footer.append("div").classed("f_navthree", true).attr("type", "button");
    footer.append("div").classed("f_navfour_click", true).attr("type", "button");
    $(".f_navone").hammer().on(touch_s, function () {
        task();
    });
    $(".f_navtwo").hammer().on(touch_s, function () {
        tzzx();
    });
    $(".f_navthree").hammer().on(touch_e, function () {
        menu();

    });
    onZhgl();
}
var onZhgl = function () {
    height = window.innerHeight;
    var data = null;
    if (window.localStorage.task && window.localStorage.task != "0") {
        d3.select(".f_navone span").html(window.localStorage.task).style({
            "opacity": 1
        });
        ;
        if (window.localStorage.task.length >= 3)
            d3.select(".f_navone span").html("99+")
                .style({
                    "opacity": 1,
                    "width": "30px"
                });
    }
    else
        d3.select(".f_navone span").remove();
    update(function (dat) {
        data = dat;
        var version = dat.versionName;
        window.plugins.getIntent.getVersion([], function (text) {
            if (text < version) {
                $("#banbgx p").html("版本更新:<b style=color:#137> (新版本)")
            } else {
                $("#banbgx p").html("版本更新:<b style=color:#137> (无更新)")
            }
        });
    }, function () {
        $("#banbgx p").html("版本更新:<b style=color:#137> (无更新)")
        data = null;
    });
    $("body").css("height", height + "px");
	 $("#mimcz").on(touch_e, function () {
		 setTimeout(function () {
       		 mimcz();
		 }, 500);
    });
	//edit by lixuefang 20160518,添加常用语设置的触发事件
	 $("#changyy").on(touch_e, function () {
		 setTimeout(function () {
       		 changyy();
		 }, 500);
    });
    $("#anqsz").on(touch_e, function () {
        anqsz();
    });
    $("#guanywm").on(touch_e, function () {
        //navigator.ca.destroy();
        guanywm();

    });
    $("#yonghbz").on(touch_e, function () {
        yonghbz();
    });
    $("#banbgx").on(touch_e, function () {

        suc(data);
    });
    var suc = function (dat) {
        //  Alert(JSON.stringify(dat));
        if (!dat) {

            var msg = ["新消息", "消息内容"];
            window.plugins.getIntent.getVersion(msg, function (text) {
                Alert("当前版本：" + text + "\n" + "暂无新版本");
            });
            return;
        }
        var msg = [];
        window.plugins.getIntent.getVersion(msg, function (text) {
            var version = dat.versionName;
            if (version <= text) {
                Alert("当前版本：" + text + "\n" + '服务器版本' + dat.versionName + "\n" + "暂无新版本");
                return;
            }
            else {
                navigator.notification.confirm("当前版本：" + text + "\n" + '服务器版本' + dat.versionName + "\n" + dat.updateInfo, showConfirm, '版本更新', ['暂不更新', '确认更新']);
                function showConfirm(button) {
                    if (button == 2) {
                        var url = serverURL + dat.apkURL;
                        //  var url = serverURL + "cmcp/static/files/android/DaTong.apk";
                        window.openF(url, "DaTong.apk");
                    }

                }
            }
        }, function () {
            Alert("获取版本信息失败");
        });
    };


}